<?php

class Ajax_IndexController extends Zend_Controller_Action
{
	private $_formData = null;

    public function init()
    {
        /* Initialize action controller here */
		$this->_helper->layout()->disableLayout();
		if($this->getRequest()->isXmlHttpRequest()) {
			$this->_formData = $this->getRequest()->getPost();
		}
		else{
			$this->_helper->viewRenderer->setNoRender(false);
			echo 'Invalid request';die();
		}
    }

    public function indexAction()
    {
        // action body
    }

    public function getCitiesAction()
    {
		if ( $this->_formData['county_id'] ){
			$modelCities = new Application_Model_Cities();
			$citiesOptions = $modelCities->getSelect($this->_formData['county_id']);
			$arr_result = array('result' => true, 'arrCities' => $citiesOptions);
		}
		else {
			$citiesOptions = array();
			$arr_result = array('result' => false, 'message' => 'Judetul selectat nu este valid');
		}
		$this->_helper->viewRenderer->setNoRender();
		$this->getResponse()->appendBody( json_encode($arr_result) );
    }


}

